<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 工厂模式
    // 优点:  可以根据传入的参数 快速生成对应的对象
    // 缺点:
    // a. 通过函数创建对象 和 函数本身 没有关联 (相对于构造函数)
    // b. 公有的属性和方法 重复声明,栈内存

    /* function cat(name, color) {
        var obj = {
            name: name,
            color: color,
            species: "猫",
            call: function () {
                console.log("喵喵");
            },
            skill() {
                console.log("捉老鼠");
            },
            say() {
                console.log(this.name, this.age);
            }
        }
        return obj;
    } */

    function Cat(name , color){
        this.name = name;
        this.color = color;
        this.species = "猫";
        this.call = function(){
            console.log("喵喵");
        };
        this.say = function(){
            console.log(this.name, this.age);
        }
    }

    var Tom = new Cat("Tom", "black");
    console.log(Tom, Tom instanceof Cat);
</script>
</html>